<template>
  <div class="index">
    <div class="subject">
      <div @click="setsubjectId(item.id)" :class="{'active':subjectId===item.id}" v-for="item in subject" :key="item.id">{{item.subject}}</div>
    </div>
    <div class="model">
      <p @click="setModel(i)" :class="{'current':Mdin===i}" v-for="(v,i) in modelType" :key="i"> {{v.text}}</p>
    </div>
  </div>
</template>
<script>
import subject from '@/configs/subject.js'
import modelType from '@/configs/model.js'
import { useStore } from 'vuex'
import { computed } from 'vue'
export default {
  name: 'modelselector',
  setup() {
    const store = useStore()
    const setModel = i => {
      store.commit('setIndex', i)
      store.commit('setModel', modelType[i].type)
    }
    const setsubjectId = id => {
      store.commit('setSubjectId', id)
    }
    return {
      subject,
      subjectId: computed(() => store.state.subjectId),
      Mdin: computed(() => store.state.Mdin),
      modelType,
      setModel,
      setsubjectId
    }
  }
}
</script>
<style lang="less" scoped>
.subject {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  color: #fff;
  > div {
    text-align: center;
    width: 150px;
    height: 100px;
    line-height: 100px;
    border-radius: 10px;
    background-color: aqua;
  }
  > div:nth-child(1) {
    background-color: #f9b04c;
  }
  > div:nth-child(2) {
    background-color: #59ab5b;
  }
}
.active {
  box-shadow: 2px 3px 5px 2px rgba(0, 0, 0, 0.5);
}
.model {
  margin: 20px 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  font-size: 16px;
  color: #2aa9db;
  p {
    width: 150px;
    text-align: center;
    height: 66px;
    margin-top: 20px;
    line-height: 60px;
    border-radius: 10px;
    border: 4px solid #2aa9db;
    box-sizing: border-box;
  }
  .current {
    background-color: #2aa9db;
    color: #fff;
  }
}
</style>
